<?php
require_once("db_functions.php");
class log_change{
	
	var $db;
	var $_log_table = "log";
	
	var $user;
	var $time;
	var $ip;
	var $state=array(
		1 => "novi",
		2 => "izmena",
		3 => "brisanje"
	);
	
	var $table;
	var $attr;
	var $value;
	
	function log_change(){
		$this->db = new db_functions();
	}
	
	function write(){
		if ($this->time<1) {
			$this->time = time();
		}
		$q = "INSERT INTO $this->_log_table "
			."VALUES($this->user,$this->time,'$this->ip','$this->table','$this->attr','$this->value',$this->state)";
		//file_put_contents("tmpvoja",$q);
		$this->db->alterTable($q);
	}
	
	
	
	//--------------------------------------------------
	
	/****************************************
	 * OLD METHODS
	 ****************************************
	
	function _write($folder="logs/"){
		//$change = var_export($this,true)."\r\n\r\n";
		
		// user	time	IP	state	table	attr	val
		$change = "$this->user\t$this->time\t$this->ip\t$this->state\t$this->table\t$this->attr\t$this->value";
		$change .= "\r\n";
		//$fp = fopen("cron","w") or die("Error opening file.");
		file_put_contents("$folder".date("dmY"),$change,FILE_APPEND);
	}
	
	function hasLog($userid){
		
		// lista korisnika cije se izmene ne loguju u stand. log file
		$skippLogging = array(
			66 => "logs/unos_",	// unos
			67 => "logs/unos1_"	// unos1
		);
		
		$ret = false;
		if (isset($skippLogging[$userid])) {
			$ret=$skippLogging[$userid];
		}
		
		return $ret;
	}
	*/
}

?>